<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子46-ES6/7常用语法介绍</title>
    </head>

    <body>
        <pre>
            <code>
                // 例子46

                class A {
                    construvtor() {
                        this.x = 'x';
                    }

                    p() {
                        return 2;
                    }
                }

                A.prototype.y = 'y'

                class B extends A {
                    constructor() {
                        super();
                        console.log(super.p()); // 2, 这里super指向A.prototype
                    }

                    get x() {
                        return super.x;
                    }

                    get	y() {
                        return super.y;
                    }
                }

                let b = new B();
                b.x; // undefined
                b.y; // "y"

                //--------------------------------------------------------------------------

                class A {
                    constructor() {
                        this.x = 1;
                    }

                    print() {
                        console.log(this.x);
                    }
                }

                class B extends A {
                    constructor() {
                        super();
                        this.x = 2;
                    }
                    m() {
                        super.print(); // 这里print方法执行时，print方法内部的this指向了子类B的实例
                    }
                }

                let b = new B();
                b.m() // 2

                //--------------------------------------------------------------------------

                class Parent {
                    static myMethod(msg) {
                        console.log('static', msg);
                    }

                    myMethod(msg) {
                        console.log('instance', msg);
                    }
                }

                class Child extends Parent {
                    static myMethod(msg) {
                        super.myMethod(msg);
                    }

                    myMethod(msg) {
                        super.myMethod(msg);
                    }
                }

                Child.myMethod(1); // static 1

                var child = new Child();
                child.myMethod(2); // instance 2

                //--------------------------------------------------------------------------

                class A {
                    constructor() {
                        this.x = 1;
                    }
                    static print() {
                        console.log(this.x);
                    }
                }

                class B extends A {
                    constructor() {
                        super();
                        this.x = 2;
                    }
                    static m() {
                        super.print();
                    }
                }

                B.x = 3;
                B.m() // 3
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/46.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>

</html>